/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cxhd.lis.ctrl;

import com.cxhd.lis.model.newmodel.lisKsdm;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.ext.route.ControllerBind;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.tx.Tx;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author 52461
 */
@ControllerBind(controllerKey = "/view/lis/ksmc")
public class KsmcCtrl extends Controller{
    
    public void index(){
    
        render("/view/lis/kswh.jsp");
    }
     public void getTempList() {
 
         renderJson(Db.use("mysql").find("select id,pId,name,isParent,open from lis_ksmctemp"));
     
 
    }
     /**
      * 显示科室信息
      */
     public void getKsmc() {
//         renderJson(Db.use("mysql").find("select PK,KSDM,KSMC,SRM1 from lis_ksdm"));
     String sql="select PK,KSDM,KSMC,SRM1";
     String param=" from lis_ksdm where KSMC like '%"+getPara("searchContent")+"%' or KSDM like '%"+getPara("searchContent")+"%'";
Page<Record> userPage = Db.use("mysql").paginate(getParaToInt("currentPage",getParaToInt("currentPage")), getParaToInt("pageSize",getParaToInt("pageSize")), sql, param);
renderJson(userPage);
         
    }
      public void getFlks() {
         renderJson(Db.use("mysql").find("select KSMC,KSDM from lis_ksdm "));
    }
      public void getKsdmId() {
         renderJson(Db.use("mysql").findFirst("select id FROM lis_ksdm where KSDM="+getPara("ksdm")));
    }
      public void checkKsdm() {
//         Record re=Db.use("mysql").findFirst("select KSDM from lis_ksdm where KSDM="+getPara("ksdm"));
          List<Record> list= Db.use("mysql").find("select * from lis_ksdm where KSMC=?",getPara("KSMC"));
       if(list.size()!=0){ 
            if(getPara("PK")!=""&&getPara("PK")!=null){//判断是新增还是修改
                if(Integer.valueOf(getPara("PK"))==list.get(0).get("PK")){ //修改是允许修改（本身主键和查询到的主键相同）
                     renderText("false");
                }else{
                   renderText("true");  
                }
            }else{
                renderText("true");
            }
        
        }else{
            renderText("false");
        }
    }
      public void saveKsdm(){
        try {
            new lisKsdm().addKsdm(this);
            renderText("true");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("false");
        }
      }
      public void updateKsdm(){
          try {
            new lisKsdm().updateKsdm(this);
            renderText("true");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("false");
        }
      }
      public void deleteKsdm(){
        try {
           new lisKsdm().deleteKsdm(getParaToInt("PK"));
          renderText("true");
        } catch (Exception ex) {
            ex.printStackTrace();
            renderText("false");
            
        }
      }
   
}
